package ru.ccfit.nsu.g7204.dronov.adPlatform;

import java.nio.ByteBuffer;

/**
 * Created by IntelliJ IDEA.
 * User: Drongo
 * Date: 14.03.11
 * Time: 11:56
 * To change this template use File | Settings | File Templates.
 */
public class UserMessageParser {
    private String uid;
    private String cnumber;

    public void parseMsg(ByteBuffer buf) throws Exception {
        if (buf.position()>0)
        {
            buf.flip();
            String tmp=new String(buf.array()).substring(0,buf.limit());
            int n=tmp.indexOf('_');
            int n2=tmp.indexOf('|');
            if (n>0 && n2>0 && n2>n)
            {
                uid=tmp.substring(0,n);
                cnumber=tmp.substring(n+1,n2);
                if (cnumber==null || uid ==null )
                    throw new Exception("Parsing error");
            }
        }
    }



    public String getUid() {
        return uid;
    }

    public String getCnumber() {
        return cnumber;
    }
}
